package com.whmnx.my.ui.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableList;

import com.whmnx.my.BR;
import com.whmnx.my.R;
import com.whmnx.my.databinding.FragmentOrderBinding;
import com.whmnx.my.ui.adapter.ViewPagerBindingAdapter;
import com.whmnx.my.ui.fragment.MyOrderFragment;

import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.binding.command.BindingConsumer;
import me.tatarka.bindingcollectionadapter2.BindingViewPagerAdapter;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

/**
 * author : huang
 * date   : 2020/9/14 0014 19:40
 * version: 1.0
 * @author Administrator
 */
public class OrderModel extends ToolbarViewModel {
    //给ViewPager添加ObservableList
    public ObservableList<ViewPagerItemViewModel> items = new ObservableArrayList<>();

    //给ViewPager添加ItemBinding
    public ItemBinding<ViewPagerItemViewModel> itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_viewpager);


    private String[] titles = new String[]{"全部","待支付","待发货","待收货","待评价","退款/售后"};

    public MyOrderFragment mFragment;
    public FragmentOrderBinding mBinding;
    private ItemBinding<ViewPagerItemViewModel> viewPagerItemViewModelItemBinding;
    private ItemBinding<ViewPagerItemViewModel> viewPagerItemViewModelItemBinding1;

    public OrderModel(@NonNull Application application) {
        super(application);
    }


    public void initToolbar(FragmentOrderBinding binding, MyOrderFragment myOrderFragment) {
        this.mBinding = binding;
        this.mFragment = myOrderFragment;
        setTitleText("我的订单");
        initUc();
    }

    private void initUc() {

    }

    public void addPage() {
        items.clear();
        //模拟3个ViewPager页面
        for (int i = 1; i <= titles.length; i++) {
            ViewPagerItemViewModel itemViewModel = new ViewPagerItemViewModel(this, i);
            items.add(itemViewModel);
        }
    }


    //给ViewPager添加PageTitle
    public final BindingViewPagerAdapter.PageTitles<ViewPagerItemViewModel> pageTitles = new BindingViewPagerAdapter.PageTitles<ViewPagerItemViewModel>() {
        @Override
        public CharSequence getPageTitle(int position, ViewPagerItemViewModel item) {
            return titles[position];
        }
    };
    //给ViewPager添加Adpter，请使用自定义的Adapter继承BindingViewPagerAdapter，重写onBindBinding方法
    public final ViewPagerBindingAdapter adapter = new ViewPagerBindingAdapter();

    //ViewPager切换监听
    public BindingCommand<Integer> onPageSelectedCommand = new BindingCommand<>(new BindingConsumer<Integer>() {
        @Override
        public void call(Integer index) {


        }
    });
}
